<?php


class HomeController extends BaseController {


	public function index($locale = '')
	{
        if(!Session::has('locale') && empty($locale)){
            $countryCode =  \Goxob\Helper::ip_info("Visitor", "Country Code");
            if($countryCode == "VN")
            {
                $locale = 'vi';
            }
            else{
                $locale = 'en';
            }
        }
        else if(empty($locale)){
            $locale = Session::get('locale');
        }

        App::setLocale($locale);
        Session::set('locale', $locale);

        $theme = Input::get('t', '3');
		return View::make('theme'.$theme);
	}

    public function postContact()
    {
        $input = Input::all();

        //validate captcha
        if(Input::has('captcha')){
            $rules =  array('captcha' => array('required', 'captcha'));
            $validator = Validator::make(Input::all(), $rules);
            if ($validator->fails())
            {
                return Redirect::to('/#contact')->withErrors(trans('Captcha does not match'))->withInput();
            }
        }


        $recipient = 'doanvuthuan@gmail.com';
        $subject = 'Goxob Home Contact Us';

        $data = $input;

        \Goxob\Email::send('emails.email_contact', $data, $recipient, $subject);

        $locale = Session::get('locale');
        return Redirect::to('/'.$locale)->with('message', trans('Your contact information was sent successfully. We will contact you shortly.'));
    }

    public function testEmail()
    {
        $input['name'] = 'THuan';
        $input['content'] = '123';
        $input['phone'] = '123';
        $input['email'] = 'thuan@gmail.com';

        $recipient = 'doanvuthuan@gmail.com';
        $subject = 'Goxob Home Contact Us';

        $data = $input;

        \Goxob\Email::send('emails.email_contact', $data, $recipient, $subject);

        return Redirect::to('/')->with('message', trans('Your contact information was sent successfully!'));
    }

}